package teach.shuji.java12.config;

import cn.dev33.satoken.exception.NotLoginException;
import jakarta.validation.ConstraintViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import teach.shuji.java12.common.CommonResult;

@RestControllerAdvice
public class NotLoginHandler {

    @ExceptionHandler({NotLoginException.class})
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public CommonResult<String> handleNotLoginException(NotLoginException ex) {
        CommonResult<String> result = new CommonResult<>();
        result.setCode(401);
        result.setMsg("请先登录");
        return result;
    }
}
